// 配置请求根路径
axios.defaults.baseURL = 'http://124.223.14.236:8060/admin'
// Do something before response is sent
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    const token = localStorage.getItem('x-token')
    if (token) {
        config.headers['x-token'] = token
    }
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(response => {
    if (response.data.errno === 9998 && response.data.errmsg === '未登录，不允许操作！') {
        location.href = './login.html'
    }
    return response
}, error => {
    // Do something with response error
    return Promise.reject(error)
})
